package com.gxc.feign;

import com.gxc.dto.Dept;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author GongXincheng
 * @since 2019-08-22 09:14
 */
@Slf4j
@Component
public class HystrixFeignFallbackFactory implements FallbackFactory<HystrixFeign> {
    @Override
    public HystrixFeign create(Throwable throwable) {
        return new HystrixFeign() {

            @Override
            public String hello() {
                log.error("hello() has Exception  ! -> {}", throwable.getMessage());
                throw new RuntimeException(throwable);
            }

            @Override
            public Dept findById(Long id) {
                Dept dept = new Dept();
                dept.setDeptNo(id);
                dept.setDeptName("FUCK");
                return dept;
            }

            @Override
            public Boolean add(Dept dept) {
                log.error("add() has Exception  ! -> {}", throwable.getMessage());
                throw new RuntimeException(throwable);
            }

            @Override
            public List<Dept> list() {
                log.error("list() has Exception  ! -> {}", throwable.getMessage());
                throw new RuntimeException(throwable);
            }

            @Override
            public Object discovery() {
                log.error("discovery() has Exception  ! ->{} ", throwable.getMessage());
                throw new RuntimeException(throwable);
            }
        };
    }
}
